package org.ruanjj.longestSubstring;

import java.util.HashSet;

public class Solution2 {
    public int lengthOfLongestSubstring(String s) {
        HashSet<Character> slidingWindow = new HashSet<>();
        int j = 0;
        int i = 0;
        int maxLength = 0;
        while(j<s.length()) {
            if (!slidingWindow.contains(s.charAt(j))) {
                slidingWindow.add(s.charAt(j));
                j++;
                maxLength = Math.max(maxLength,slidingWindow.size());
            } else {
                slidingWindow.remove(s.charAt(i));
                i++;
            }
        }
        return maxLength;
    }
}
